<?php

namespace app\api\controller\v49;

use app\api\controller\v13\Auth2;
use app\common\cachemodel\ai_chat_room\AiChatRecord;
use app\common\cachemodel\ZlUserVip;
use think\Cache;

class AiChat extends Auth2
{
    public function getChatModeList()
    {
        $type = input('type/d', 0);
        $vipLevel = $this->user ? (new ZlUserVip())->getUserVipLevel($this->user['id']) : 0;
        if ($this->user)
        {
            request()->get(['page' => 1, 'limit' => 1]);
            $cacheKey = 'ai_chat_room:create_skip:user:' . $this->user['id'];
            $isSkip = Cache::get($cacheKey);
            if ($isSkip)
            {
                $link3 = 'heal_chat_room_list?need_auth=2';
            } else
            {
                $aiChatRecordModel = new AiChatRecord();
                $aiChatRecordModel->setPageLimit(1);
                $pageData = $aiChatRecordModel->getListPage($this->user['id'], 'update_time', [], 0, 'desc', 0);
                $link3 = $pageData['total'] > 0 ? 'heal_chat_room_list?need_auth=2' : 'heal_chat_room_create?need_auth=0';
            }
        } else
        {
            $link3 = 'heal_chat_room_create?need_auth=0';
        }

        $resData = [
            [
                'icon' => '/test/ai/chat_model1.png',
                'name' => '专业咨询师',
                'desc' => '你的最强占星助手',
                'tip_url' => '',
                'target' => 'local',
                'link' => 'aichat?type=0&need_auth=0',
                'is_must_vip' => 0,
                'is_selected' => $type === 1 ? 1 : 0,
            ], [
                'icon' => '/test/ai/chat_model2.png',
                'name' => '星座女神',
                'desc' => '莫小奇智能语音分身（beta版）',
                'tip_url' => '/test/ai/model_vip.png',
                'target' => 'local',
                'link' => $vipLevel ? 'call_aichat?need_auth=1' : 'pay_order?type=8&need_auth=2',
                'is_must_vip' => 1,
                'is_selected' => $type === 2 ? 1 : 0,
            ], [
                'icon' => '/test/ai/chat_model3.png',
                'name' => '疗愈陪聊师',
                'desc' => '时刻陪伴你的朋友',
                'tip_url' => '',
                'target' => 'local',
                'link' => $link3,
                'is_must_vip' => 0,
                'is_selected' => $type === 3 ? 1 : 0,
            ],
        ];

        return show(config('code.success'), '请求成功', $resData);
    }
}